package com.ssyx.activity.controller;

import com.ssyx.activity.service.ActivityInfoService;
import com.ssyx.activity.service.CouponInfoService;
import com.ssyx.model.activity.CouponInfo;
import com.ssyx.model.activity.CouponUse;
import com.ssyx.model.order.CartInfo;
import com.ssyx.vo.order.CartInfoVo;
import com.ssyx.vo.order.OrderConfirmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName:activityInnerController
 * Description:
 *
 * @Author kay
 * @Create 2024/5/16 17:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/activity")
public class ActivityInnerController {

    @Autowired
    private ActivityInfoService activityInfoService;

    @Autowired
    private CouponInfoService couponInfoService;

    //根据skuId列表获取促销信息
    @PostMapping("inner/findActivity")
    public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList) {
        return activityInfoService.findActivity(skuIdList);
    }

    //根据skuId,userId,获取促销与优惠券信息
    @GetMapping("inner/findActivityAndCoupon/{skuId}/{userId}")
    public Map<String, Object> findActivityAndCoupon(@PathVariable Long skuId, @PathVariable("userId") Long userId) {
        Map<String, Object> map = activityInfoService.findActivityAndCoupon(skuId, userId);
        return map;
    }

    //获取购物车满足条件的促销与优惠券信息
    @PostMapping("inner/findCartActivityAndCoupon/{userId}")
    public OrderConfirmVo findCartActivityAndCoupon(@RequestBody List<CartInfo> cartInfoList,
                                                    @PathVariable("userId") Long userId) {
        OrderConfirmVo orderConfirmVo = activityInfoService.findCartActivityAndCoupon(cartInfoList, userId);
        return orderConfirmVo;
    }

    //根据购物车列表,获取相关优惠活动信息 封装在CartInfoVo中
    @PostMapping("inner/findCartActivityList")
    public List<CartInfoVo> findCartActivityList(@RequestBody List<CartInfo> cartInfoList) {
        List<CartInfoVo> CartInfoVoList = activityInfoService.findCartActivityList(cartInfoList);
        return CartInfoVoList;
    }

    //根据购物车列表,以及用户的优惠券id,得到购物车商品使用优惠券的相关规则信息
    @PostMapping("inner/findRangeSkuIdList/{couponId}")
    public CouponInfo findRangeSkuIdList(@RequestBody List<CartInfo> cartInfoList,
                                         @PathVariable Long couponId){
        CouponInfo couponInfo = couponInfoService.findRangeSkuIdList(cartInfoList,couponId);
        return couponInfo;
    }

    //订单生成之后,修改优惠券使用状态
    @GetMapping("inner/updateCouponInfoUseStatus/{couponId}/{orderId}/{userId}")
    public void updateCouponInfoUseStatus(@PathVariable Long couponId,
                                          @PathVariable Long orderId,
                                          @PathVariable Long userId){
       couponInfoService.updateCouponInfoUseStatus(couponId,orderId,userId);
    }

}
